<?php
// +----------------------------------------------------------------------
// | NewThink [ Think More,Think Better! ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2018 http://www.newthink.cc All rights reserved.
// +----------------------------------------------------------------------
// | 版权所有：山西创泰网络科技有限公司
// +----------------------------------------------------------------------
// | Author: 燕南天 QQ:81020302 Date:2018-08-01 Time:17:21
// +----------------------------------------------------------------------

namespace app\api\controller\v1;


use app\api\controller\Base;

class Login extends Base
{
    /**
     * @title 登陆
     * @description 本接口用于用户登陆
     * @author 燕南天
     * @url  /api/login
     * @method POST
     * @param_send name:dispatch_id type:int require:1 default:15000002 desc:班次编号ID
     * @param_send name:charge_id type:int require:1 default:17000002 desc:收费员ID
     * @param_return code:200,msg
     * @param_return charge_name:收费员姓名
     * @param_return charge_token:收费员登录码
     */
    public function login(){
        if ($this->request->isAjax()) {
            
            //数据库字段 网页字段转换
            $param = [
                'username' => 'username',
                'password' => 'password',
            ];
            $param_data = $this->buildParam($param);
            
            $check_login = $this->doModelAction($param_data, 'base/PersonnelUser.login', 'base/PersonnelUser', 'checkLogin');
            //记录错误信息
            if (!isset($check_login['code'])) $this->showReturnCodeWithSaveLog(1111);
            
            if ($check_login['code'] == 1001) {
                //设置全局登录
                $this->setLoginGlobal($check_login['data'], 1);
            }
            return $check_login;
        }else{
            return $this->fetch("login");
        }
    }
}